﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Roslyn.Compilers;
using Roslyn.Compilers.Common;
using Roslyn.Services;

namespace Analysis.Rules
{
    class ObjectInvocationIsSimpleTypeVolatileChecker : IVolatileChecker
    {
        private IRoslynHelper helper;

        public ObjectInvocationIsSimpleTypeVolatileChecker(IRoslynHelper helper)
        {
            this.helper = helper;
        }

        public bool IsVolatile(CommonSyntaxNode node, IDocument doc)
        {
            var ts = helper.GetTypeAndSymbol(node, doc);

            var allowedSpecialTypes = new[]
            {
                SpecialType.System_Boolean, 
                SpecialType.System_Byte, 
                SpecialType.System_Char, 
                SpecialType.System_DateTime, 
                SpecialType.System_Decimal, 
                SpecialType.System_Double, 
                SpecialType.System_Enum, 
                SpecialType.System_Int16,
                SpecialType.System_Int32,
                SpecialType.System_Int64
            };

            if (ts.Item1 == null)
                return false;
            return !allowedSpecialTypes.Contains(ts.Item1.SpecialType);
        }
    }
}
